package com.example.demo;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @Description
 * @Author
 * @Date 2019/8/22 20:31
 **/
public class ThreadDemo {
    private  static int WORKER_POOL_SIZE=2;
    private static ExecutorService workerPool =  new ThreadPoolExecutor(WORKER_POOL_SIZE, 10,
            0L, TimeUnit.MILLISECONDS,
            new LinkedBlockingQueue<Runnable>(5),new ThreadPoolFactory("ThreadDemoThread"), new ThreadPoolExecutor.AbortPolicy());
    public static void main(String[] args) throws Exception{
        for (int i=0;i<20;i++){
            workerPool.submit(new Runnable() {
                @Override
                public void run() {

                    try {
                        Thread.sleep(10000L);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                    System.out.println(Thread.currentThread().getName()+System.currentTimeMillis());
                }
            });
        }

    }
}
